package com.koron.log.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.common.core.business.log.entity.po.LogOperatePo;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.log.service.LogOperateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (LogOperate)表控制层
 *
 * @author zhouj
 * @since 2022-06-08 11:53:56
 */
@Api(tags = "(LogOperate)")
@RestController
@RequestMapping("/logOperate/")
public class LogOperateController {

    @Autowired
    private LogOperateService logOperateService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("insertOrUpdate")
    public Response<Integer> insertOrUpdate(@CasUser EamUser user, @RequestBody LogOperatePo logOperate) {


        return Response.ok(logOperateService.insertOrUpdate(logOperate));
    }

    @ApiOperation(value = "新增")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody LogOperatePo logOperate) {
        return Response.ok(logOperateService.insert(logOperate));
    }

    @ApiOperation(value = "批量新增")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<LogOperatePo> logOperateList) {
        return Response.ok(logOperateService.insertBatch(logOperateList));
    }

    @ApiOperation(value = "根据id更新")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody LogOperatePo logOperate) {
        return Response.ok(logOperateService.update(logOperate));
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(logOperateService.deleteById(id));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("queryById")
    public Response<LogOperatePo> queryById(String id) {
        return Response.ok(logOperateService.queryById(id));
    }

    @ApiOperation(value = "不分页查询列表")
    @GetMapping("queryList")
    public Response<List<LogOperatePo>> queryList(LogOperatePo queryVo) {
        return Response.ok(logOperateService.queryList(queryVo));
    }

    @ApiOperation(value = "分页查询列表")
    @GetMapping("queryPageList")
    public Response<PageInfo> queryPageList(LogOperatePo queryPo, PageQuery pageQuery) {
        return Response.ok(logOperateService.queryPageList(queryPo,pageQuery));
    }

}
